package com.zhongnan.demo2;

public class SearchArray {
    public static void main(String[] args) {
        // 二分查找  对象的索引
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        int num = 3;
        int min = 0;
        int max = arr.length - 1;
        while (min <= max) {
            int mid = (min + max) >> 1;
            if (arr[mid] == num) {
                System.out.println(mid);
                break;
            } else if (arr[mid] > num) {
                max = mid - 1;
            } else if (arr[mid] < num) {
                min = mid + 1;
            }
        }
    }
}
